package app.engine.solucoes.request.command;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import app.engine.solucoes.request.beans.Resposta;
import app.engine.solucoes.request.exception.CommandException;

public class NewAnswerCommand implements Command {

	private String next;

	public NewAnswerCommand(String next) {
		this.next = next;
	}

	@Override
	public String execute(HttpServletRequest req) throws CommandException {
		GetCommand getAllCommand = new GetCommand(next);
		next = getAllCommand.execute(req);
		req.setAttribute("idPergunta", req.getParameter("idPergunta"));
		List<Resposta> respostas = (List<Resposta>) req.getSession().getAttribute("respostas");
		Resposta resposta = new Resposta();
		resposta.setTxtResposta("");
		resposta.setAprovada(Boolean.FALSE);
		resposta.setId(-1l);
		respostas.add(resposta);
		return next;
	}

}
